﻿<div class="fitem_auto padding_H" id="Root">
    <div v-show="msg" class="msgbox_alert">{{msg}}</div>
    <div v-show="active">
        <buttonlist :hook="hooks[0]" :set="sets[0]" class="wyjcontainer_H border_B padding_V"></buttonlist>
        <pagenation :hook="hooks[1]" :set="table" :api="Api" hasToolbar="yes">
            <template #toolbar="postData">
                <input placeholder="请输入库位编码" v-model="postData.queryKeys.key" />
            </template>
            <template #td="models">
                <td><a class="tooltip" @@click="Switch(3, models.model)">{{models.model.Code}}<span class="tooltiptext">查看详情</span></a></td>
                <td>{{models.model.Name}}</td>
                <td>{{models.model.Customer.Name}}</td>
                <td>
                    <a v-for="(btn,i) in icons" :key="i" :class="btn.class" @@click="btn.act(models.model)"><i :class="btn.icon"></i></a>
                </td>
            </template>
        </pagenation>
    </div>
    <div v-show="!active" class="exclusive wyjcontainer_V">
        <buttonlist :hook="hooks[2]" :set="sets[1]" class="wyjcontainer_HL border_B padding_V"></buttonlist>
        <editor :hook="hooks[3]" :set="labels">
            <template v-if="viewMode" #ele>
                <div class="formGroup_ele" v-for="(y,x) in labels" :key="x">{{model[x].Name || model[x]}}</div>
            </template>
            <template v-else #ele="slotProps">
                <input class="formGroup_ele" v-model="model.Code" placeholder="请输入库位编码" />
                <input class="formGroup_ele" v-model="model.Name" placeholder="请输入库位名称" />
                <select class="formGroup_ele" v-model="Customer.Id">
                    <option value="">请选择客户</option>
                    @{ 
                        var options = WYJWeb.Models.BaseInfo.Customer.GetAll();
                        foreach (var option in options)
                        {
                            <option value="@option.Key">@option.Value.Name</option>
                        }
                    }
                </select>
            </template>
            <template #subtmpl>
            </template>
        </editor>
        <buttonlist :hook="hooks[4]" :set="sets[2]" class="wyjcontainer_HM padding_V border_T"></buttonlist>
    </div>
</div>

@section foot {
    <script type="text/javascript">
        var app = new App({
            Api: 'StockSpace',
            table: {
                titles: ["库位编码", "库位名称", "所属客户", "操作"],
            },
            PageTitles: ['库位列表', '新增库位', '编辑库位', '查看库位'],
            icons: [{
                icon:'fa fa-trash',
                act: (e, i) => {
                    app.DeleteById(e.Id, i)
                }
            }, {
                icon:'fa fa-pencil-square-o',            
                act: (e) => {
                    app.Switch(2, e);
                }
            }],
            labels: {
                Code: '库位编码',
                Name:'库位名称',
                Customer:'所属客户'
            },
            Customer: { Id: '' }
        });
        app.BeforeSave = function(model){
            model.Customer = this.Customer;
            console.log(model);
            return model;
        }
    </script>
}